<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>main.cpp 示例文件 | Qt Widgets 5.12.3</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.12</a></td><td ><a href="qtwidgets-index.html">Qt Widgets</a></td><td ><a href="qtwidgets-mainwindows-mainwindow-example.html">Main Window</a></td><td >main.cpp 示例文件</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtwidgets-index.html">Qt 5.12.3 参考指南</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar"><div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">main.cpp 示例文件</h1>
<span class="subtitle">mainwindows/mainwindow/main.cpp</span>
<!-- $$$mainwindows/mainwindow/main.cpp-description -->
<div class="descr"> <a name="details"></a>
<pre class="cpp">

  <span class="comment">/****************************************************************************
  **
  ** Copyright (C) 2016 The Qt Company Ltd.
  ** Contact: https://www.qt.io/licensing/
  **
  ** This file is part of the demonstration applications of the Qt Toolkit.
  **
  ** $QT_BEGIN_LICENSE:BSD$
  ** Commercial License Usage
  ** Licensees holding valid commercial Qt licenses may use this file in
  ** accordance with the commercial license agreement provided with the
  ** Software or, alternatively, in accordance with the terms contained in
  ** a written agreement between you and The Qt Company. For licensing terms
  ** and conditions see https://www.qt.io/terms-conditions. For further
  ** information use the contact form at https://www.qt.io/contact-us.
  **
  ** BSD License Usage
  ** Alternatively, you may use this file under the terms of the BSD license
  ** as follows:
  **
  ** &quot;Redistribution and use in source and binary forms, with or without
  ** modification, are permitted provided that the following conditions are
  ** met:
  **   * Redistributions of source code must retain the above copyright
  **     notice, this list of conditions and the following disclaimer.
  **   * Redistributions in binary form must reproduce the above copyright
  **     notice, this list of conditions and the following disclaimer in
  **     the documentation and/or other materials provided with the
  **     distribution.
  **   * Neither the name of The Qt Company Ltd nor the names of its
  **     contributors may be used to endorse or promote products derived
  **     from this software without specific prior written permission.
  **
  **
  ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  ** &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&quot;
  **
  ** $QT_END_LICENSE$
  **
  ****************************************************************************/</span>

  <span class="preprocessor">#include &quot;mainwindow.h&quot;</span>

  <span class="preprocessor">#include &lt;QApplication&gt;</span>
  <span class="preprocessor">#include &lt;QPainterPath&gt;</span>
  <span class="preprocessor">#include &lt;QPainter&gt;</span>
  <span class="preprocessor">#include &lt;QMap&gt;</span>
  <span class="preprocessor">#include &lt;QDebug&gt;</span>

  <span class="type">void</span> render_qt_text(<span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span> <span class="operator">*</span>painter<span class="operator">,</span> <span class="type">int</span> w<span class="operator">,</span> <span class="type">int</span> h<span class="operator">,</span> <span class="keyword">const</span> <span class="type"><a href="../qtgui/qcolor.html">QColor</a></span> <span class="operator">&amp;</span>color)
  {
      <span class="type"><a href="../qtgui/qpainterpath.html">QPainterPath</a></span> path;
      path<span class="operator">.</span>moveTo(<span class="operator">-</span><span class="number">0.083695</span><span class="operator">,</span> <span class="number">0.283849</span>);
      path<span class="operator">.</span>cubicTo(<span class="operator">-</span><span class="number">0.049581</span><span class="operator">,</span> <span class="number">0.349613</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.012720</span><span class="operator">,</span> <span class="number">0.397969</span><span class="operator">,</span> <span class="number">0.026886</span><span class="operator">,</span> <span class="number">0.428917</span>);
      path<span class="operator">.</span>cubicTo(<span class="number">0.066493</span><span class="operator">,</span> <span class="number">0.459865</span><span class="operator">,</span> <span class="number">0.111593</span><span class="operator">,</span> <span class="number">0.477595</span><span class="operator">,</span> <span class="number">0.162186</span><span class="operator">,</span> <span class="number">0.482108</span>);
      path<span class="operator">.</span>lineTo(<span class="number">0.162186</span><span class="operator">,</span> <span class="number">0.500000</span>);
      path<span class="operator">.</span>cubicTo(<span class="number">0.115929</span><span class="operator">,</span> <span class="number">0.498066</span><span class="operator">,</span> <span class="number">0.066565</span><span class="operator">,</span> <span class="number">0.487669</span><span class="operator">,</span> <span class="number">0.014094</span><span class="operator">,</span> <span class="number">0.468810</span>);
      path<span class="operator">.</span>cubicTo(<span class="operator">-</span><span class="number">0.038378</span><span class="operator">,</span> <span class="number">0.449952</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.088103</span><span class="operator">,</span> <span class="number">0.423839</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.135082</span><span class="operator">,</span> <span class="number">0.390474</span>);
      path<span class="operator">.</span>cubicTo(<span class="operator">-</span><span class="number">0.182061</span><span class="operator">,</span> <span class="number">0.357108</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.222608</span><span class="operator">,</span> <span class="number">0.321567</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.256722</span><span class="operator">,</span> <span class="number">0.283849</span>);
      path<span class="operator">.</span>cubicTo(<span class="operator">-</span><span class="number">0.304712</span><span class="operator">,</span> <span class="number">0.262250</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.342874</span><span class="operator">,</span> <span class="number">0.239362</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.371206</span><span class="operator">,</span> <span class="number">0.215184</span>);
      path<span class="operator">.</span>cubicTo(<span class="operator">-</span><span class="number">0.411969</span><span class="operator">,</span> <span class="number">0.179078</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.443625</span><span class="operator">,</span> <span class="number">0.134671</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.466175</span><span class="operator">,</span> <span class="number">0.081963</span>);
      path<span class="operator">.</span>cubicTo(<span class="operator">-</span><span class="number">0.488725</span><span class="operator">,</span> <span class="number">0.029255</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.500000</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.033043</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.500000</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.104932</span>);
      path<span class="operator">.</span>cubicTo(<span class="operator">-</span><span class="number">0.500000</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.218407</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.467042</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.312621</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.401127</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.387573</span>);
      path<span class="operator">.</span>cubicTo(<span class="operator">-</span><span class="number">0.335212</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.462524</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.255421</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.500000</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.161752</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.500000</span>);
      path<span class="operator">.</span>cubicTo(<span class="operator">-</span><span class="number">0.072998</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.500000</span><span class="operator">,</span> <span class="number">0.003903</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.462444</span><span class="operator">,</span> <span class="number">0.068951</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.387331</span>);
      path<span class="operator">.</span>cubicTo(<span class="number">0.133998</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.312218</span><span class="operator">,</span> <span class="number">0.166522</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.217440</span><span class="operator">,</span> <span class="number">0.166522</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.102998</span>);
      path<span class="operator">.</span>cubicTo(<span class="number">0.166522</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.010155</span><span class="operator">,</span> <span class="number">0.143394</span><span class="operator">,</span> <span class="number">0.071325</span><span class="operator">,</span> <span class="number">0.097138</span><span class="operator">,</span> <span class="number">0.141441</span>);
      path<span class="operator">.</span>cubicTo(<span class="number">0.050882</span><span class="operator">,</span> <span class="number">0.211557</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.009396</span><span class="operator">,</span> <span class="number">0.259026</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.083695</span><span class="operator">,</span> <span class="number">0.283849</span>);
      path<span class="operator">.</span>moveTo(<span class="operator">-</span><span class="number">0.167823</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.456963</span>);
      path<span class="operator">.</span>cubicTo(<span class="operator">-</span><span class="number">0.228823</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.456963</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.277826</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.432624</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.314831</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.383946</span>);
      path<span class="operator">.</span>cubicTo(<span class="operator">-</span><span class="number">0.361665</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.323340</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.385082</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.230335</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.385082</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.104932</span>);
      path<span class="operator">.</span>cubicTo(<span class="operator">-</span><span class="number">0.385082</span><span class="operator">,</span> <span class="number">0.017569</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.361376</span><span class="operator">,</span> <span class="number">0.112025</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.313964</span><span class="operator">,</span> <span class="number">0.178433</span>);
      path<span class="operator">.</span>cubicTo(<span class="operator">-</span><span class="number">0.277248</span><span class="operator">,</span> <span class="number">0.229368</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.228534</span><span class="operator">,</span> <span class="number">0.254836</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.167823</span><span class="operator">,</span> <span class="number">0.254836</span>);
      path<span class="operator">.</span>cubicTo(<span class="operator">-</span><span class="number">0.105088</span><span class="operator">,</span> <span class="number">0.254836</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.054496</span><span class="operator">,</span> <span class="number">0.229368</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.016045</span><span class="operator">,</span> <span class="number">0.178433</span>);
      path<span class="operator">.</span>cubicTo(<span class="number">0.029055</span><span class="operator">,</span> <span class="number">0.117827</span><span class="operator">,</span> <span class="number">0.051605</span><span class="operator">,</span> <span class="number">0.028691</span><span class="operator">,</span> <span class="number">0.051605</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.088975</span>);
      path<span class="operator">.</span>cubicTo(<span class="number">0.051605</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.179562</span><span class="operator">,</span> <span class="number">0.039318</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.255803</span><span class="operator">,</span> <span class="number">0.014744</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.317698</span>);
      path<span class="operator">.</span>cubicTo(<span class="operator">-</span><span class="number">0.004337</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.365409</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.029705</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.400548</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.061362</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.423114</span>);
      path<span class="operator">.</span>cubicTo(<span class="operator">-</span><span class="number">0.093018</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.445680</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.128505</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.456963</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.167823</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.456963</span>);
      path<span class="operator">.</span>moveTo(<span class="number">0.379011</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.404739</span>);
      path<span class="operator">.</span>lineTo(<span class="number">0.379011</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.236460</span>);
      path<span class="operator">.</span>lineTo(<span class="number">0.486123</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.236460</span>);
      path<span class="operator">.</span>lineTo(<span class="number">0.486123</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.197292</span>);
      path<span class="operator">.</span>lineTo(<span class="number">0.379011</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.197292</span>);
      path<span class="operator">.</span>lineTo(<span class="number">0.379011</span><span class="operator">,</span> <span class="number">0.134913</span>);
      path<span class="operator">.</span>cubicTo(<span class="number">0.379011</span><span class="operator">,</span> <span class="number">0.168117</span><span class="operator">,</span> <span class="number">0.383276</span><span class="operator">,</span> <span class="number">0.190442</span><span class="operator">,</span> <span class="number">0.391804</span><span class="operator">,</span> <span class="number">0.201886</span>);
      path<span class="operator">.</span>cubicTo(<span class="number">0.400332</span><span class="operator">,</span> <span class="number">0.213330</span><span class="operator">,</span> <span class="number">0.411246</span><span class="operator">,</span> <span class="number">0.219052</span><span class="operator">,</span> <span class="number">0.424545</span><span class="operator">,</span> <span class="number">0.219052</span>);
      path<span class="operator">.</span>cubicTo(<span class="number">0.435531</span><span class="operator">,</span> <span class="number">0.219052</span><span class="operator">,</span> <span class="number">0.446227</span><span class="operator">,</span> <span class="number">0.215264</span><span class="operator">,</span> <span class="number">0.456635</span><span class="operator">,</span> <span class="number">0.207689</span>);
      path<span class="operator">.</span>cubicTo(<span class="number">0.467042</span><span class="operator">,</span> <span class="number">0.200113</span><span class="operator">,</span> <span class="number">0.474993</span><span class="operator">,</span> <span class="number">0.188910</span><span class="operator">,</span> <span class="number">0.480486</span><span class="operator">,</span> <span class="number">0.174081</span>);
      path<span class="operator">.</span>lineTo(<span class="number">0.500000</span><span class="operator">,</span> <span class="number">0.174081</span>);
      path<span class="operator">.</span>cubicTo(<span class="number">0.488436</span><span class="operator">,</span> <span class="number">0.210509</span><span class="operator">,</span> <span class="number">0.471957</span><span class="operator">,</span> <span class="number">0.237911</span><span class="operator">,</span> <span class="number">0.450564</span><span class="operator">,</span> <span class="number">0.256286</span>);
      path<span class="operator">.</span>cubicTo(<span class="number">0.429170</span><span class="operator">,</span> <span class="number">0.274662</span><span class="operator">,</span> <span class="number">0.407054</span><span class="operator">,</span> <span class="number">0.283849</span><span class="operator">,</span> <span class="number">0.384215</span><span class="operator">,</span> <span class="number">0.283849</span>);
      path<span class="operator">.</span>cubicTo(<span class="number">0.368893</span><span class="operator">,</span> <span class="number">0.283849</span><span class="operator">,</span> <span class="number">0.353859</span><span class="operator">,</span> <span class="number">0.279094</span><span class="operator">,</span> <span class="number">0.339115</span><span class="operator">,</span> <span class="number">0.269584</span>);
      path<span class="operator">.</span>cubicTo(<span class="number">0.324371</span><span class="operator">,</span> <span class="number">0.260074</span><span class="operator">,</span> <span class="number">0.313530</span><span class="operator">,</span> <span class="number">0.246534</span><span class="operator">,</span> <span class="number">0.306592</span><span class="operator">,</span> <span class="number">0.228965</span>);
      path<span class="operator">.</span>cubicTo(<span class="number">0.299653</span><span class="operator">,</span> <span class="number">0.211396</span><span class="operator">,</span> <span class="number">0.296184</span><span class="operator">,</span> <span class="number">0.184075</span><span class="operator">,</span> <span class="number">0.296184</span><span class="operator">,</span> <span class="number">0.147002</span>);
      path<span class="operator">.</span>lineTo(<span class="number">0.296184</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.197292</span>);
      path<span class="operator">.</span>lineTo(<span class="number">0.223330</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.197292</span>);
      path<span class="operator">.</span>lineTo(<span class="number">0.223330</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.215667</span>);
      path<span class="operator">.</span>cubicTo(<span class="number">0.241833</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.224049</span><span class="operator">,</span> <span class="number">0.260697</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.237992</span><span class="operator">,</span> <span class="number">0.279922</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.257495</span>);
      path<span class="operator">.</span>cubicTo(<span class="number">0.299147</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.276999</span><span class="operator">,</span> <span class="number">0.316276</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.300129</span><span class="operator">,</span> <span class="number">0.331310</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.326886</span>);
      path<span class="operator">.</span>cubicTo(<span class="number">0.338826</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.341070</span><span class="operator">,</span> <span class="number">0.349523</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.367021</span><span class="operator">,</span> <span class="number">0.363400</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.404739</span>);
      path<span class="operator">.</span>lineTo(<span class="number">0.379011</span><span class="operator">,</span> <span class="operator">-</span><span class="number">0.404739</span>);
      path<span class="operator">.</span>moveTo(<span class="operator">-</span><span class="number">0.535993</span><span class="operator">,</span> <span class="number">0.275629</span>);

      painter<span class="operator">-</span><span class="operator">&gt;</span>translate(w <span class="operator">/</span> <span class="number">2</span><span class="operator">,</span> h <span class="operator">/</span> <span class="number">2</span>);
      <span class="type">double</span> scale <span class="operator">=</span> <a href="../qtcore/qtglobal.html#qMin">qMin</a>(w<span class="operator">,</span> h) <span class="operator">*</span> <span class="number">8</span> <span class="operator">/</span> <span class="number">10.0</span>;
      painter<span class="operator">-</span><span class="operator">&gt;</span>scale(scale<span class="operator">,</span> scale);

      painter<span class="operator">-</span><span class="operator">&gt;</span>setRenderHint(<span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>Antialiasing);

      painter<span class="operator">-</span><span class="operator">&gt;</span>save();
      painter<span class="operator">-</span><span class="operator">&gt;</span>translate(<span class="operator">.</span><span class="number">1</span><span class="operator">,</span> <span class="operator">.</span><span class="number">1</span>);
      painter<span class="operator">-</span><span class="operator">&gt;</span>fillPath(path<span class="operator">,</span> <span class="type"><a href="../qtgui/qcolor.html">QColor</a></span>(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">63</span>));
      painter<span class="operator">-</span><span class="operator">&gt;</span>restore();

      painter<span class="operator">-</span><span class="operator">&gt;</span>setBrush(color);
      painter<span class="operator">-</span><span class="operator">&gt;</span>setPen(<span class="type"><a href="../qtgui/qpen.html">QPen</a></span>(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>black<span class="operator">,</span> <span class="number">0.02</span><span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>SolidLine<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>FlatCap<span class="operator">,</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>RoundJoin));
      painter<span class="operator">-</span><span class="operator">&gt;</span>drawPath(path);
  }

  <span class="keyword">static</span> <span class="type">void</span> usage()
  {
      <a href="../qtcore/qtglobal.html#qWarning">qWarning</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">&quot;Usage: mainwindow [-SizeHint&lt;color&gt; &lt;width&gt;x&lt;height&gt;] ...&quot;</span>;
      exit(<span class="number">1</span>);
  }

  <span class="keyword">enum</span> ParseCommandLineArgumentsResult {
      CommandLineArgumentsOk<span class="operator">,</span>
      CommandLineArgumentsError<span class="operator">,</span>
      HelpRequested
  };

  <span class="keyword">static</span> ParseCommandLineArgumentsResult
      parseCustomSizeHints(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstringlist.html">QStringList</a></span> <span class="operator">&amp;</span>arguments<span class="operator">,</span> MainWindow<span class="operator">::</span>CustomSizeHintMap <span class="operator">*</span>result)
  {
      result<span class="operator">-</span><span class="operator">&gt;</span>clear();
      <span class="keyword">const</span> <span class="type">int</span> argumentCount <span class="operator">=</span> arguments<span class="operator">.</span>size();
      <span class="keyword">for</span> (<span class="type">int</span> i <span class="operator">=</span> <span class="number">1</span>; i <span class="operator">&lt;</span> argumentCount; <span class="operator">+</span><span class="operator">+</span>i) {
          <span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&amp;</span>arg <span class="operator">=</span> arguments<span class="operator">.</span>at(i);
          <span class="keyword">if</span> (arg<span class="operator">.</span>startsWith(QLatin1String(<span class="string">&quot;-SizeHint&quot;</span>))) {
              <span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> name <span class="operator">=</span> arg<span class="operator">.</span>mid(<span class="number">9</span>);
              <span class="keyword">if</span> (name<span class="operator">.</span>isEmpty())
                  <span class="keyword">return</span> CommandLineArgumentsError;
              <span class="keyword">if</span> (<span class="operator">+</span><span class="operator">+</span>i <span class="operator">=</span><span class="operator">=</span> argumentCount)
                  <span class="keyword">return</span> CommandLineArgumentsError;
              <span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> sizeStr <span class="operator">=</span> arguments<span class="operator">.</span>at(i);
              <span class="keyword">const</span> <span class="type">int</span> idx <span class="operator">=</span> sizeStr<span class="operator">.</span>indexOf(QLatin1Char(<span class="char">'x'</span>));
              <span class="keyword">if</span> (idx <span class="operator">=</span><span class="operator">=</span> <span class="operator">-</span><span class="number">1</span>)
                  <span class="keyword">return</span> CommandLineArgumentsError;
              bool ok;
              <span class="keyword">const</span> <span class="type">int</span> w <span class="operator">=</span> sizeStr<span class="operator">.</span>leftRef(idx)<span class="operator">.</span>toInt(<span class="operator">&amp;</span>ok);
              <span class="keyword">if</span> (<span class="operator">!</span>ok)
                  <span class="keyword">return</span> CommandLineArgumentsError;
              <span class="keyword">const</span> <span class="type">int</span> h <span class="operator">=</span> sizeStr<span class="operator">.</span>midRef(idx <span class="operator">+</span> <span class="number">1</span>)<span class="operator">.</span>toInt(<span class="operator">&amp;</span>ok);
              <span class="keyword">if</span> (<span class="operator">!</span>ok)
                  <span class="keyword">return</span> CommandLineArgumentsError;
              result<span class="operator">-</span><span class="operator">&gt;</span>insert(name<span class="operator">,</span> <span class="type"><a href="../qtcore/qsize.html">QSize</a></span>(w<span class="operator">,</span> h));
          } <span class="keyword">else</span> <span class="keyword">if</span> (arg <span class="operator">=</span><span class="operator">=</span> QLatin1String(<span class="string">&quot;-h&quot;</span>) <span class="operator">|</span><span class="operator">|</span> arg <span class="operator">=</span><span class="operator">=</span> QLatin1String(<span class="string">&quot;--help&quot;</span>)) {
              <span class="keyword">return</span> HelpRequested;
          } <span class="keyword">else</span> {
              <span class="keyword">return</span> CommandLineArgumentsError;
          }
      }

      <span class="keyword">return</span> CommandLineArgumentsOk;
  }

  <span class="type">int</span> main(<span class="type">int</span> argc<span class="operator">,</span> <span class="type">char</span> <span class="operator">*</span><span class="operator">*</span>argv)
  {
      <span class="type"><a href="qapplication.html">QApplication</a></span><span class="operator">::</span>setAttribute(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AA_EnableHighDpiScaling);
      <span class="type"><a href="qapplication.html">QApplication</a></span><span class="operator">::</span>setAttribute(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>AA_UseHighDpiPixmaps);
      <span class="type"><a href="qapplication.html">QApplication</a></span> app(argc<span class="operator">,</span> argv);
      MainWindow<span class="operator">::</span>CustomSizeHintMap customSizeHints;
      <span class="keyword">switch</span> (parseCustomSizeHints(<span class="type"><a href="../qtcore/qcoreapplication.html">QCoreApplication</a></span><span class="operator">::</span>arguments()<span class="operator">,</span> <span class="operator">&amp;</span>customSizeHints)) {
      <span class="keyword">case</span> CommandLineArgumentsOk:
          <span class="keyword">break</span>;
      <span class="keyword">case</span> CommandLineArgumentsError:
          usage();
          <span class="keyword">return</span> <span class="operator">-</span><span class="number">1</span>;
      <span class="keyword">case</span> HelpRequested:
          usage();
          <span class="keyword">return</span> <span class="number">0</span>;
      }
      MainWindow mainWin(customSizeHints);
      mainWin<span class="operator">.</span>resize(<span class="number">800</span><span class="operator">,</span> <span class="number">600</span>);
      mainWin<span class="operator">.</span>show();
      <span class="keyword">return</span> app<span class="operator">.</span>exec();
  }

</pre>
</div>
<!-- @@@mainwindows/mainwindow/main.cpp -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
